package com.bharat.web.managedBeans;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;

import com.bharat.domain.Test;
import com.bharat.services.TestService;

public class TestManagedBean implements Serializable{

	private static final long serialVersionUID = 398444067007266701L;

	private Test test;
	
	private List<Test> tests;
	
	private TestService testService;
	
	
	public TestManagedBean() {
		this.test = new Test();
		this.tests = new ArrayList<Test>();
	}

	public Test getTest() {
		return test;
	}
	
	public void setTest(Test test) {
		this.test = test;
	}

	public List<Test> getTests() {
		return tests;
	}

	public void setTests(List<Test> tests) {
		this.tests = tests;
	}
	
	public void setTestService(TestService testService) {
		this.testService = testService;
	}

	
	/**
	 * 
	 */
	public void addTest(){
		System.out.println("add test.............");
		System.out.println(test.getTestName());
		System.out.println(test.getTestFee());
		int status = this.testService.createTest(test);
		if (status == 1){
			this.test = new Test();
		}
	}

	public void editTest(Test test){
		System.out.println("Edit Test "+ test);
		test.setEditable(true);
		this.test = test;
	}
	
	public void deleteTest(Test test){
		System.out.println("delete test "+ test);
		this.testService.deleteTest(test);
	}
	
	public void updateTest(Test test){
		System.out.println("Update test : "+ test);
		testService.updateTest(test);
		this.test = new Test();
	}
	
	public List<Test> getAllTests(){
		tests = this.testService.getAllTests();
		return tests;
	}
	
	@PostConstruct
	private void loadAllTests(){
		System.out.println("post construct........");
	}
	
}
